<template>
    <div>
        <hr>
        <h5>我是孙组件</h5>
        <p>
            <button @click="clickEvent">我传递值给所有监听事件的组件</button>
        </p>
        <p>
            <button @click="receiveEvent">先监听再发送！！！</button>
        </p>
        <hr>
    </div>
</template>

<script>
    export default {
        methods:{
            clickEvent(){
                this.$root.eventBus.$emit('listen',1);
            },
            receiveEvent(){
                //点击以后触发一个全局监听
                this.$root.eventBus.$on('created',function(){
                console.log("全局事件监听");
                console.log(arguments);
                })
            }
        }
    }
</script>

<style scoped>
    h5{
        color: rgb(12, 236, 162);
    }
</style>